﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace MPS.Migrations
{
    /// <inheritdoc />
    public partial class import_DanikorModules : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "DK_EnumDefinition",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Code = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    Name = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    SortId = table.Column<int>(type: "int", nullable: false),
                    Description = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
                    Status = table.Column<bool>(type: "bit", nullable: false),
                    ParentEnumDefinitionId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_EnumDefinition", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DK_FormAttachment",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    BusinessFormId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    BusinessFormSubReference = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    FormFileId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    FileName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    Sort = table.Column<int>(type: "int", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_FormAttachment", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DK_FormDefinition",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    FormId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    FormDisplayName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    FormName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    FormApplyUrl = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    FormApproveUrl = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    FormViewUrl = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    FormListUrl = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    FormSize = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    FormApplyScript = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    FormApproveScript = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    FormViewScript = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    FormScriptUrl = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    FormTitleTemplate = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    WorkflowDefinitionId = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    WorkflowVersion = table.Column<int>(type: "int", nullable: false),
                    WorkflowName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    Subject = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    IsPublished = table.Column<bool>(type: "bit", nullable: false),
                    CheckPermission = table.Column<bool>(type: "bit", nullable: false),
                    Version = table.Column<int>(type: "int", nullable: false),
                    IsLatest = table.Column<bool>(type: "bit", nullable: false),
                    EnableTemporary = table.Column<bool>(type: "bit", nullable: false),
                    EnableWithDrew = table.Column<bool>(type: "bit", nullable: false),
                    JoinOaTodo = table.Column<bool>(type: "bit", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_FormDefinition", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DK_FormFile",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ReferenceId = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    BlobName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    FileName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    MimeType = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
                    Size = table.Column<long>(type: "bigint", nullable: false),
                    CreatorName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_FormFile", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DK_FormInstance",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ApplicantCode = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    ApplicantName = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    ApplicantDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CompletionDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    FormStatus = table.Column<int>(type: "int", nullable: false),
                    WorkflowInstanceId = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    FormDefinitionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Title = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    BusinessFormId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    FormData = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_FormInstance", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DK_SerialNumberDefinitions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Code = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    Name = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    Status = table.Column<bool>(type: "bit", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_SerialNumberDefinitions", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DK_SerialNumberInstances",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    DefinitionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SerialNumber = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_SerialNumberInstances", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DK_SerialNumberResetInstances",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SerialNumberDefinitionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    RuleDefinitionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ResetKey = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    CurrentNumber = table.Column<int>(type: "int", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_SerialNumberResetInstances", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MessageManagementEventMessage",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    EventName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                    Subject = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    MessageMediaId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MessageTemplateName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Status = table.Column<bool>(type: "bit", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MessageManagementEventMessage", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MessageManagementMessageBox",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MessageMediaId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ApplicationName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    Subject = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    Content = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ToUser = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    CcUser = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true),
                    Queue = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    IsSend = table.Column<bool>(type: "bit", nullable: false),
                    SendTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    IsRead = table.Column<bool>(type: "bit", nullable: false),
                    ReadTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MessageManagementMessageBox", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MessageManagementMessageMedia",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SenderName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SenderArgs = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true),
                    Description = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true),
                    EnableMessageBox = table.Column<bool>(type: "bit", nullable: false),
                    Status = table.Column<bool>(type: "bit", nullable: false),
                    IsDefault = table.Column<bool>(type: "bit", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MessageManagementMessageMedia", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MessageManagementMessageTemplate",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    TemplateContent = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Description = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true),
                    IsLayout = table.Column<bool>(type: "bit", nullable: false),
                    LayoutName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MessageManagementMessageTemplate", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DK_EnumDefinitionItem",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    EnumDefinitionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    EnumItemText = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    EnumItemValue = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    SortId = table.Column<int>(type: "int", nullable: false),
                    Status = table.Column<bool>(type: "bit", nullable: false),
                    Description = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_EnumDefinitionItem", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DK_EnumDefinitionItem_DK_EnumDefinition_EnumDefinitionId",
                        column: x => x.EnumDefinitionId,
                        principalTable: "DK_EnumDefinition",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "DK_FormDefinitionActivity",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    FormDefinitionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ActivityId = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    ActivityType = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    ActivityName = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    TodoReminder = table.Column<bool>(type: "bit", nullable: false),
                    DoneReminder = table.Column<bool>(type: "bit", nullable: false),
                    CloseReminder = table.Column<bool>(type: "bit", nullable: false),
                    IsFirstActiviy = table.Column<bool>(type: "bit", nullable: false),
                    UserActions = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_FormDefinitionActivity", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DK_FormDefinitionActivity_DK_FormDefinition_FormDefinitionId",
                        column: x => x.FormDefinitionId,
                        principalTable: "DK_FormDefinition",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "DK_FormDefinitionConfiguration",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    FormDefinitionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    IsSkipWhenUserSameWithPreviousActivityUser = table.Column<bool>(type: "bit", nullable: false),
                    EnableTodoReminder = table.Column<bool>(type: "bit", nullable: false),
                    EnableDoneReminder = table.Column<bool>(type: "bit", nullable: false),
                    EnableCloseReminder = table.Column<bool>(type: "bit", nullable: false),
                    CloseReminderMailList = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_FormDefinitionConfiguration", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DK_FormDefinitionConfiguration_DK_FormDefinition_FormDefinitionId",
                        column: x => x.FormDefinitionId,
                        principalTable: "DK_FormDefinition",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "DK_FormDefinitionControl",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    FormDefinitionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ActivityId = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    ActivityName = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    PropertyCompositeName = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: false),
                    PropertyName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    PropertyType = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    Sort = table.Column<int>(type: "int", nullable: false),
                    Readable = table.Column<bool>(type: "bit", nullable: false),
                    Writable = table.Column<bool>(type: "bit", nullable: false),
                    Suppressible = table.Column<bool>(type: "bit", nullable: false),
                    Required = table.Column<bool>(type: "bit", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_FormDefinitionControl", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DK_FormDefinitionControl_DK_FormDefinition_FormDefinitionId",
                        column: x => x.FormDefinitionId,
                        principalTable: "DK_FormDefinition",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "DK_FormInstanceTransaction",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    FormInstanceId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ActivityId = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    ActivityType = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    ActivityName = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    ArriveTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UserCode = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    UserName = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    UserAction = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    UserRemark = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    Remark = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
                    State = table.Column<bool>(type: "bit", nullable: false),
                    CompleteTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Sequence = table.Column<int>(type: "int", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_FormInstanceTransaction", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DK_FormInstanceTransaction_DK_FormInstance_FormInstanceId",
                        column: x => x.FormInstanceId,
                        principalTable: "DK_FormInstance",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "DK_RuleDefinitions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SerialNumberDefinitionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Type = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    State = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    SortId = table.Column<int>(type: "int", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_RuleDefinitions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DK_RuleDefinitions_DK_SerialNumberDefinitions_SerialNumberDefinitionId",
                        column: x => x.SerialNumberDefinitionId,
                        principalTable: "DK_SerialNumberDefinitions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "DK_SerialNumberConfigurations",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SerialNumberDefinitionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TemplateFile = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    DataFile = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    PrinterName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    PrintQuantity = table.Column<int>(type: "int", nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_SerialNumberConfigurations", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DK_SerialNumberConfigurations_DK_SerialNumberDefinitions_SerialNumberDefinitionId",
                        column: x => x.SerialNumberDefinitionId,
                        principalTable: "DK_SerialNumberDefinitions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "DK_RuleInstances",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SerialNumberInstanceId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    RuleDefinitionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SerialNumber = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DK_RuleInstances", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DK_RuleInstances_DK_SerialNumberInstances_SerialNumberInstanceId",
                        column: x => x.SerialNumberInstanceId,
                        principalTable: "DK_SerialNumberInstances",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_DK_EnumDefinition_Code",
                table: "DK_EnumDefinition",
                column: "Code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_DK_EnumDefinitionItem_EnumDefinitionId",
                table: "DK_EnumDefinitionItem",
                column: "EnumDefinitionId");

            migrationBuilder.CreateIndex(
                name: "IX_DK_FormDefinition_FormId_Version",
                table: "DK_FormDefinition",
                columns: new[] { "FormId", "Version" });

            migrationBuilder.CreateIndex(
                name: "IX_DK_FormDefinitionActivity_FormDefinitionId",
                table: "DK_FormDefinitionActivity",
                column: "FormDefinitionId");

            migrationBuilder.CreateIndex(
                name: "IX_DK_FormDefinitionConfiguration_FormDefinitionId",
                table: "DK_FormDefinitionConfiguration",
                column: "FormDefinitionId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_DK_FormDefinitionControl_FormDefinitionId",
                table: "DK_FormDefinitionControl",
                column: "FormDefinitionId");

            migrationBuilder.CreateIndex(
                name: "IX_DK_FormInstanceTransaction_FormInstanceId",
                table: "DK_FormInstanceTransaction",
                column: "FormInstanceId");

            migrationBuilder.CreateIndex(
                name: "IX_DK_RuleDefinitions_SerialNumberDefinitionId",
                table: "DK_RuleDefinitions",
                column: "SerialNumberDefinitionId");

            migrationBuilder.CreateIndex(
                name: "IX_DK_RuleInstances_SerialNumberInstanceId",
                table: "DK_RuleInstances",
                column: "SerialNumberInstanceId");

            migrationBuilder.CreateIndex(
                name: "IX_DK_SerialNumberConfigurations_SerialNumberDefinitionId",
                table: "DK_SerialNumberConfigurations",
                column: "SerialNumberDefinitionId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_DK_SerialNumberDefinitions_Code",
                table: "DK_SerialNumberDefinitions",
                column: "Code");

            migrationBuilder.CreateIndex(
                name: "IX_DK_SerialNumberInstances_DefinitionId",
                table: "DK_SerialNumberInstances",
                column: "DefinitionId");

            migrationBuilder.CreateIndex(
                name: "IX_DK_SerialNumberResetInstances_SerialNumberDefinitionId_RuleDefinitionId_ResetKey",
                table: "DK_SerialNumberResetInstances",
                columns: new[] { "SerialNumberDefinitionId", "RuleDefinitionId", "ResetKey" });
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "DK_EnumDefinitionItem");

            migrationBuilder.DropTable(
                name: "DK_FormAttachment");

            migrationBuilder.DropTable(
                name: "DK_FormDefinitionActivity");

            migrationBuilder.DropTable(
                name: "DK_FormDefinitionConfiguration");

            migrationBuilder.DropTable(
                name: "DK_FormDefinitionControl");

            migrationBuilder.DropTable(
                name: "DK_FormFile");

            migrationBuilder.DropTable(
                name: "DK_FormInstanceTransaction");

            migrationBuilder.DropTable(
                name: "DK_RuleDefinitions");

            migrationBuilder.DropTable(
                name: "DK_RuleInstances");

            migrationBuilder.DropTable(
                name: "DK_SerialNumberConfigurations");

            migrationBuilder.DropTable(
                name: "DK_SerialNumberResetInstances");

            migrationBuilder.DropTable(
                name: "MessageManagementEventMessage");

            migrationBuilder.DropTable(
                name: "MessageManagementMessageBox");

            migrationBuilder.DropTable(
                name: "MessageManagementMessageMedia");

            migrationBuilder.DropTable(
                name: "MessageManagementMessageTemplate");

            migrationBuilder.DropTable(
                name: "DK_EnumDefinition");

            migrationBuilder.DropTable(
                name: "DK_FormDefinition");

            migrationBuilder.DropTable(
                name: "DK_FormInstance");

            migrationBuilder.DropTable(
                name: "DK_SerialNumberInstances");

            migrationBuilder.DropTable(
                name: "DK_SerialNumberDefinitions");
        }
    }
}
